import { FormSchema } from '/@/components/Table';
import { testModelConfig } from './modelAiSet.api';
export const columns = [
  {
    title: '配置名称',
    dataIndex: 'apiName',
    width: 100,
  },
  {
    title: '模型名称',
    dataIndex: 'modelName',
    width: 100,
  },
  {
    title: '描述',
    dataIndex: 'description',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 100,
  },
];
/**
 * 角色用户Columns
 */
export const userColumns = [
  {
    title: '用户账号',
    dataIndex: 'username',
  },
  {
    title: '用户姓名',
    dataIndex: 'realname',
  },
  {
    title: '状态',
    dataIndex: 'status_dictText',
    width: 80,
  },
];
export const searchFormSchema: FormSchema[] = [
  {
    field: 'apiName',
    label: '配置名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'modelName',
    label: '模型名称',
    component: 'Input',
    colProps: { span: 6 },
  },
];
/**
 * 角色用户搜索form
 */
export const searchUserFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '用户账号',
    component: 'Input',
    colProps: { span: 12 },
    labelWidth: 74,
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  {
    field: 'apiName',
    label: '配置名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'modelName',
    label: '模型名称',
    required: true,
    component: 'Input',
    dynamicRules: ({ values }) => {
      return [
        {
          required: true,
          validator: (_, value) => {
            if (!value) {
              return Promise.reject('请输入模型名称');
            }
            if (values) {
              return new Promise((resolve, reject) => {
                testModelConfig({ modelName: values })
                  .then((res) => {
                    res.message ? resolve() : reject('校验失败');
                  })
                  .catch((err) => {
                    reject(err.message || '验证失败');
                  });
              });
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
  {
    label: '配置描述',
    field: 'description',
    component: 'InputTextArea',
  },
];

export const formDescSchema = [
  {
    field: 'roleName',
    label: '角色名称',
  },
  {
    field: 'roleCode',
    label: '角色编码',
  },
  {
    label: '备注',
    field: 'description',
  },
];

export const modelFormSchema: FormSchema[] = [
  {
    label: 'APIkey',
    field: 'apiKey',
    component: 'Input',
    required: true,
    helpMessage: '请输入APIkey',
  },
];